package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.LoginDto;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.system.LoginVo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin/system/index")
@RestController
public class IndexController {

    @Autowired
    SysUserService sysUserService;

    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto, HttpServletRequest request){
        // 调用业务层验证用户名密码
        String ip = request.getRemoteAddr();
        LoginVo loginVo = sysUserService.login(loginDto, ip);
        if (loginVo == null){
            return Result.fail("用户名或密码错误");
        } else {
            return Result.ok(loginVo);
        }

    }
}
